# -*- coding: utf-8 -*-

import os,subprocess

# 在mac下安装protoc的编译器
#1.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#2.brew install protobuf-swift

SOURCE_PATH = u'./'
TARGET_PATH = '../../PokerApp/PokerApp/Source/Proto'
CMD_GEN = r'protoc'

def doConvertFile(path):
	print(os.path.abspath(path))
	dirname = os.path.dirname(path)
	filename = os.path.basename(path);
	cmd = 'protoc {0} --swift_out="{1}"'.format(filename, TARGET_PATH);
	#print(cmd)
	os.system(cmd);


def doConvert(path):
	if not os.path.exists(TARGET_PATH):
		os.makedirs(TARGET_PATH)

	for root, dirs, files in os.walk(path):
		for file in files:
			if file.endswith('.proto'):
				doConvertFile(os.path.join(root, file))


doConvert(SOURCE_PATH)

